package com.gupao.javavip.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.UUID;

public class NettyClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("应答数据：" + msg);
    }

    @Override
    public void channelActive(ChannelHandlerContext channel) throws Exception {
        //生成一个随机的ID
        String s = UUID.randomUUID().toString();
        System.out.println("客户端发送数据：" + s);
        channel.writeAndFlush(s);

//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String in = br.readLine();
//        System.out.println("客户端发送数据：" + in);
//        while (!(in.equals("再见") || in.equals("bye"))) {
//            channel.writeAndFlush(in);
//            in = br.readLine();
//        }
//        channel.writeAndFlush(in);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
